package bb.lanxing.databinding.sprint;

import androidx.core.content.ContextCompat;
import androidx.databinding.Bindable;
import bb.lanxing.App;
import bb.lanxing.R;
import bb.lanxing.lib.devices.core.sync.DeviceFile;
import bb.lanxing.lib.devices.core.sync.DeviceFileStatus;
import bb.lanxing.util.AppFileUtils;

public class DeviceSyncItem2 extends DeviceSyncItem {
    public DeviceSyncItem2(DeviceFile deviceFile) {
        super(deviceFile);
    }

    public DeviceSyncItem2() {
    }

    @Override
    public boolean getShowProgressBar() {
        DeviceFileStatus vFileStatus = DeviceFileStatus.valueOf(getStatus());
        return vFileStatus == DeviceFileStatus.STATUS_SYNCING;
    }

    @Override
    @Bindable
    public String getStatusText() {
        int strId;
        DeviceFile deviceFile = getDeviceFile();
        DeviceFileStatus vFileStatus = DeviceFileStatus.valueOf(getStatus());
        if (vFileStatus == null) {
            vFileStatus = DeviceFileStatus.STATUS_NONE;
        }

        switch (vFileStatus) {
            case STATUS_SYNC_FAIL -> strId = (int) R.string.str_sync_failed;
            case STATUS_SYNCING -> strId = (int) R.string.str_sync_import_data;
            case STATUS_SYNCED -> strId = (int) R.string.str_sync_already_exists;
            case STATUS_SYNC_PENDING -> strId = (int) R.string.str_sync_pending;
            default -> {
                strId = (int) R.string.str_sync_not_exists;
                if (AppFileUtils.isFileExists(deviceFile.getPath())) {
                    strId = (int) R.string.str_sync_already_exists;
                }
            }
        }
        return App.getContext().getString(strId);
    }

    @Override
    @Bindable
    public Integer getStatusTextColor() {
        if (AppFileUtils.isFileExists(getDeviceFile().getPath())) {
            return ContextCompat.getColor(App.getContext(), R.color.common_blue);
        }
        DeviceFileStatus vFileStatus = DeviceFileStatus.valueOf(getStatus());
        if (vFileStatus == null) {
            vFileStatus = DeviceFileStatus.STATUS_NONE;
        }

        if (vFileStatus == DeviceFileStatus.STATUS_SYNCING
                || vFileStatus == DeviceFileStatus.STATUS_SYNCED
                || vFileStatus == DeviceFileStatus.STATUS_SYNC_PENDING) {
            return ContextCompat.getColor(App.getContext(), R.color.common_blue);
        }
        return ContextCompat.getColor(App.getContext(), R.color.common_red);
    }
}
